<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎使用奥多户外</view>
			<u-input type="email" v-model="email" :border="true" placeholder="邮箱" />
			<br>
			<u-input type="password" v-model="password" border placeholder="密码" />
			<br>
			<!-- <button @tap="submit" :style="[inputStyle]" class="getCaptcha">获取短信验证码</button> -->
			<u-button :type="button_type" @click="login" :loading="loading">{{loginText}}</u-button>
			<view class="alternative">
				<view class="issue" @click="toRegister">还没有账号呢</view>
				<view class="issue">遇到问题</view>
			</view>
		</view>
		<view class="buttom">
			<view class="loginType">
				<view class="wechat item">
					<view class="icon"><u-icon size="70" name="weixin-fill" color="rgb(83,194,64)"></u-icon></view>
					微信
				</view>
				<view class="QQ item">
					<view class="icon"><u-icon size="70" name="qq-fill" color="rgb(17,183,233)"></u-icon></view>
					QQ
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import helper from '../../config/helper.js'
	import proxy from '../../config/proxy.js'
	export default {
		data() {
			return {
				button_type: "primary",
				email: "",
				password: "",
				device: "",
				loading: false,
				loginText: "登录"
			}
		},
		onLoad() {
			this.device = helper.device
		},
		methods: {
			toRegister: function() {
				uni.navigateTo({
					url: '/pages/register/register'
				})
			},
			login: function() {
				this.loading = true
				uni.request({
					// url: 'http://47.106.81.45/user/',
					url: proxy.host + 'user/',
					method: 'POST',
					header: {
						'Content-Type': 'application/json'
					},
					data: {
						email: this.email,
						password: this.password,
						device: this.device
					},
					success: (res) => {
						if (res.statusCode == 200) {
							
							this.loading = false
							this.button_type = 'success'
							this.loginText = '登录成功'
							// 将cookie写入缓存
							uni.setStorage({
								key: "login",
								data: res.header['Set-Cookie']
							})
						} else {
							this.loading = false
							this.button_type = 'error'
							this.loginText = res.data.errMsg
							// setTimeout(function() {
							// 	this.button_type = 'primary'
							// 	this.loginText = '请重试一下吧~'
							// }, 2000)
						}
					}
				})
			},
		}
	};
</script>

<style lang="scss" scoped>
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;

		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-type-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		.getCaptcha {
			background-color: rgb(253, 243, 208);
			color: $u-tips-color;
			border: none;
			font-size: 30rpx;
			padding: 12rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		.loginType {
			display: flex;
			padding: 350rpx 150rpx 150rpx 150rpx;
			justify-content:space-between;
			
			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: $u-content-color;
				font-size: 28rpx;
			}
		}
		
		.hint {
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: $u-tips-color;
			
			.link {
				color: $u-type-warning;
			}
		}
	}
}
</style>
